<?php

namespace App\Http\Controllers\Api\V1\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB; 

class ScreenResource extends JsonResource
{
    public function toArray($request)
    {
        $resource = $this->resource;

        if($resource->type == "brand"){
             $res = DB::table($resource->type."s")->where("is_shown",1)->get();
         }else{

             $res = DB::table($resource->type."s")->get();
         }
       

        foreach($res as  &$v){
            if(isset($v->image)){

                 $v->image = img_path($v->image);
            }
           
        }
    
        return [
            'id'                => (int)$resource->id,
            'title'                => $resource->title,
            'type'             => $resource->type,
            'order'              => $resource->order,
            'active'           => -1,
            'type_res'          => $res,
            'created_at'          =>(string)$resource->created_at,
            
        ];
    }
}
